package com.mashibing.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.mashibing.common.utils.PageUtils;
import com.mashibing.common.utils.R;
import com.mashibing.mall.product.param.AttributeParam;
import com.mashibing.mall.product.vo.AttrResponseVo;
import com.mashibing.mall.product.vo.AttrVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.mashibing.mall.product.service.AttrService;

import javax.validation.Valid;


/**
 * 商品属性 控制器
 *
 * @author ROGzhongyang
 * @email inspiron149@163.com
 * @date 2024-11-18 18:50:24
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {

    @Autowired
    private AttrService attrService;

    /**
     * 商品属性(规格参数、销售属性) - 分页
     */
    @GetMapping("/{attrType}/list/{catelogId}")
    public R baseList(@RequestParam Map<String, Object> params
            ,@PathVariable("catelogId") Long catelogId
            ,@PathVariable("attrType") String attrType
    ){
        PageUtils page =attrService.queryBasePage(params,catelogId,attrType);
        return R.ok().put("page",page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //        @RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 商品规格参数 - 详情
     */
    @RequestMapping("/info/{attrId}")
    //        @RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrResponseVo attr = attrService.detail(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 规格参数 - 新增
     */
    @RequestMapping("/save")
    //        @RequiresPermissions("product:attr:save")
    public R save(@Validated(AttributeParam.AttrAdd.class) @RequestBody AttributeParam attributeParam){
		attrService.add(attributeParam);
        return R.ok();
    }

    /**
     * 商品规格参数 - 编辑
     */
    @RequestMapping("/update")
    //        @RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVO attrVO){
		attrService.edit(attrVO);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //        @RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
